//利用管道接收到流，并发送给mpg123  播放音乐
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define BUFSIZE 1024


int main(){

    int pd[2]; 
    pid_t pid;
    int len;
    char buf[BUFSIZE];

    if (pipe(pd) < 0){
        perror("pipe ()");
        exit(1);
    }

    pid= fork(); 
    if (pid<0){
        perror("fork()");
        exit(1);
    }

    if(pid == 0 ){       //子进程 读
        close(pd [1];
        dup2 (pd[0]);      //重定向文件描述符
        close(pd[0]);  
        fd = open ("/dev/null",O_RDWR);
        dup2 (fd, 1);
        dup2 (fd, 2);
        execl("/usr/local/bin/mpg123", "mpg123","-",NULL);
        perror("execl()");
        exit(1);
    } 
    else{               // 父进程 写
        close(pd[0]); 
        //父进程从网上收数据，负责往写端写数据
        write(pd [1],"Hello!",6);
        close(pd [1]); wait (NULL)
        exit (0);
    }


}